home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / LIFE6__ / PROTO / P / PUTILS_L.C < prev    next >
Text File  |  1991-08-16  |  5KB  |  141 lines

  1. /*  PUtils_Life6                                                             Utilities
  2.  
  3. File name:  PUtils_Life6.C  
  4. Function:  Utilities for the Prototyper specific code.
  5. History: 8/16/91 Original by Prototyper 3.0   */
  6.  
  7.  
  8.  
  9. #include "PCommonLife6.h"    /* Common */
  10. #include "Common_Life6.h"    /* Common */
  11. #include "PUtils_Life6.h"    /* This file */
  12.  
  13. /* ======================================================= */
  14.  
  15. /* Routine: TrapAvailable */
  16. /* Purpose: See if trap is available, non-available traps all have a unique address */
  17.  
  18. Boolean TrapAvailable (trapNumber,tType)                             /* See if a trap is available */
  19. short    trapNumber;
  20. short    tType;
  21. {
  22.         #define UnimplementedTrapNumber     0xA89F                  /* Unimplemented trap number */
  23.         Boolean    theResult;
  24.  
  25.         theResult = (NGetTrapAddress(trapNumber, tType) != GetTrapAddress(UnimplementedTrapNumber));/* Check the two traps */
  26.         return(theResult);
  27. }
  28.  
  29.  
  30. /* ======================================================= */
  31.  
  32. /* Routine: GetUserEvent */
  33. /* Purpose: See if any user events are available */
  34.  
  35. void GetUserEvent(UserEventPRec TheUserEvent)
  36.         UserEventHRec    NextUserEvent;                                  /* The next user event */
  37.  
  38.         TheUserEvent->ID = UserEvent_None;                             /* Set ID to no events are available */
  39.         if (UserEventList != NIL)                                             /* Get first entry in the list */
  40.             {
  41.                 HLock((Handle)UserEventList);                               /* Lock for safety */
  42.                 TheUserEvent->ID = (*UserEventList)->ID;                 /* The event ID */
  43.                 TheUserEvent->ID2 = (*UserEventList)->ID2;             /* The optional ID */
  44.                 TheUserEvent->Data1 = (*UserEventList)->Data1;/* The optional data */
  45.                 TheUserEvent->Data2 = (*UserEventList)->Data2;/* The optional data */
  46.                 TheUserEvent->theHandle = (*UserEventList)->theHandle;/* The optional handle */
  47.                 NextUserEvent = (*UserEventList)->Next;                 /* The next list */
  48.  
  49.                 DisposHandle((Handle)UserEventList);                       /* Remove this list item */
  50.                 UserEventList = NextUserEvent;                             /* Make the next item the new first item */
  51.             }
  52. }
  53.  
  54.  
  55. /* ======================================================= */
  56.  
  57. /* Routine: Add_UserEvent */
  58. /* Purpose: Add a user event */
  59.  
  60. void Add_UserEvent( ID,  ID2, Data1, Data2,  theHandle)
  61. short        ID;
  62. short        ID2;
  63. long        Data1;
  64. long        Data2;
  65. Handle    theHandle;
  66.         UserEventHRec    NewUserEvent;                                   /* The new user event */
  67.         UserEventHRec    theUserEvent;                                    /* The user event */
  68.  
  69.         NewUserEvent = (UserEventHRec)NewHandle(sizeof(UserEventRec));/* Allocate a record */
  70.         if (NewUserEvent != NIL)                                             /* Only do if we got the new record */
  71.             {
  72.                 HLock((Handle)NewUserEvent);                               /* Lock for safety */
  73.                 (*NewUserEvent)->ID = ID;                                   /* The event ID */
  74.                 (*NewUserEvent)->ID2 = ID2;                                /* The optional ID */
  75.                 (*NewUserEvent)->Data1 = Data1;                          /* The optional data */
  76.                 (*NewUserEvent)->Data2 = Data2;                          /* The optional data */
  77.                 (*NewUserEvent)->theHandle = theHandle;                 /* The optional handle */
  78.                 (*NewUserEvent)->Next = NIL;                              /* No next item after this one */
  79.  
  80.                 if (UserEventList == NIL)                                      /* See if anyone is in the list yet */
  81.                     UserEventList = NewUserEvent;                          /* Make this one the first in the list */
  82.                 else                                                               /* Not the first in the list */
  83.                     {
  84.                         theUserEvent = UserEventList;                         /* Get the first one */
  85.                         while ((*theUserEvent)->Next != NIL)                 /* Get the next one */
  86.                         {
  87.                                 theUserEvent = (*theUserEvent)->Next;
  88.                         }
  89.                         (*theUserEvent)->Next = NewUserEvent;            /* Tack on to the end */
  90.                     }
  91.             }
  92. }
  93.  
  94. /* ======================================================= */
  95.  
  96.  
  97. /* Setup a dialog or alert item */ 
  98. void SetupTheItem( theDialog, ItemID, SizeIt, ShowIt,EnableIt,SetTheMax,thePosition, ExtraData, StringID)
  99. DialogPtr    theDialog;
  100. short        ItemID;
  101. Boolean        SizeIt;
  102. Boolean        ShowIt;
  103. Boolean        EnableIt;
  104. Boolean        SetTheMax;
  105. Rect        *thePosition;
  106. long        ExtraData;
  107. short        StringID;
  108. {
  109.         Rect        tempRect;                                                  /* Temporary rectangle */
  110.         short    DType;                                                         /* Type of dialog item */
  111.         Handle    DItem;                                                        /* Handle to the dialog item */
  112.         ControlHandle    CItem;                                               /* Control handle */
  113.  
  114.         GetDItem(theDialog,ItemID,&DType,&DItem,&tempRect);/* Get the item handle and size */
  115.         CItem = (ControlHandle)DItem;                                     /* Change to control handle */
  116.         if (SizeIt)                                                               /* Have to resize all CDEF connected controls */
  117.             SizeControl(CItem, tempRect.right-tempRect.left, tempRect.bottom-tempRect.top);/* Size it */
  118.         *thePosition = tempRect;                                            /* Pass back the zone location and size */
  119.         if (ExtraData != NIL)                                                  /* See if extra data for a CDEF */
  120.             (*CItem)->contrlData = (Handle)ExtraData;                   /* Send it */
  121.         if (StringID != 0)                                                      /* See if a CDEF and needs the title set again*/
  122.             {
  123.                 GetIndString(sTemp,StringID,1);                             /* Get the string */
  124.                 SetCTitle(CItem,sTemp);                                      /* Set the string */
  125.             }
  126.         if (EnableIt)                                                             /* See if enable or disable the zone */
  127.             HiliteControl (CItem,0);                                          /* Enable the zone */
  128.         else
  129.             HiliteControl (CItem,255);                                       /* Dim the zone */
  130.         if (SetTheMax)
  131.             SetCtlMax(CItem,12345);                                        /* Set the flag to the CDEF */
  132.         if (ShowIt)
  133.             ShowControl(CItem);                                              /* Show it to activate it */
  134.  
  135. }
  136.  
  137. /* ======================================================= */
  138.  
  139.